/*
 * @Descripttion: GGB
 * @version: 1.0
 * @Author: GGB
 * @Date: 2021-08-20 07:17:21
 * @LastEditors: GGB
 * @LastEditTime: 2021-08-20 22:13:35
 */

import 'package:flutter/material.dart';
import 'package:flutter_data_center/utills/color_utils.dart';
import 'package:table_calendar/table_calendar.dart';

class CustomCalendar extends StatelessWidget {
  const CustomCalendar({
    Key key,
    this.selectedDay,
    this.focusedDay,
    this.onDaySelected,
    this.calendarFormat,
    this.onFormatChanged,
    this.headerVisible = true,
  }) : super(key: key);
  final DateTime selectedDay;
  final DateTime focusedDay;
  final Function(DateTime, DateTime) onDaySelected;
  final CalendarFormat calendarFormat;
  final Function(CalendarFormat) onFormatChanged;
  final bool headerVisible;

  @override
  Widget build(BuildContext context) => TableCalendar(
        firstDay: DateTime.utc(2010, 10, 16),
        lastDay: DateTime.now(),
        locale: "zh-CN",
        headerVisible: headerVisible,
        daysOfWeekVisible: true,
        pageJumpingEnabled: false,
        // 配置顶部的样式
        headerStyle: HeaderStyle(
          titleCentered: false,
          formatButtonVisible: false,
          leftChevronPadding: EdgeInsets.all(0),
          leftChevronMargin: EdgeInsets.all(4),
          leftChevronIcon: SizedBox(),
          rightChevronIcon: SizedBox(),
          titleTextStyle: TextStyle(
            fontSize: 24,
            color: Colors.black,
            fontWeight: FontWeight.w700,
          ),
        ),
        // 配置星期的样式
        daysOfWeekStyle: DaysOfWeekStyle(
          weekdayStyle: TextStyle(
            color: gColor("#BABABA"),
            fontSize: 14,
            fontWeight: FontWeight.w700,
          ),
          weekendStyle: TextStyle(
            color: gColor("#BABABA"),
            fontSize: 14,
            fontWeight: FontWeight.w700,
          ),
        ),
        // 配置日历的样式
        calendarStyle: CalendarStyle(
          defaultTextStyle: TextStyle(
            color: Colors.black,
            fontSize: 18,
            fontWeight: FontWeight.w700,
          ),
          todayTextStyle: TextStyle(
            color: Colors.white,
            fontSize: 18,
            fontWeight: FontWeight.w700,
          ),
          todayDecoration: BoxDecoration(
            color: Theme.of(context).primaryColor,
            // borderRadius: BorderRadius.circular(8),
            shape: BoxShape.circle,
          ),
          selectedTextStyle: TextStyle(
            color: Colors.white,
            fontSize: 18,
            fontWeight: FontWeight.w700,
          ),
          selectedDecoration: BoxDecoration(
            color: Theme.of(context).primaryColor.withOpacity(0.6),
            // borderRadius: BorderRadius.circular(8),
            shape: BoxShape.circle,
          ),
          defaultDecoration: BoxDecoration(shape: BoxShape.circle),
        ),
        startingDayOfWeek: StartingDayOfWeek.monday,
        calendarFormat: calendarFormat ?? CalendarFormat.week,
        focusedDay: focusedDay ?? DateTime.now(),
        selectedDayPredicate: (day) {
          return isSameDay(selectedDay, day);
        },
        onFormatChanged: onFormatChanged,
        onDaySelected: onDaySelected,
      );
}
